package com.qin.entity.components;

import com.qin.common.RegexProcessor;
import com.qin.entity.ExecuteBean;
import com.qin.entity.ExecuteLog;
import com.qin.service.ExecuteService;
import com.qin.service.impl.ExecuteServiceImpl;

public class LogComponent {

    //输出日志
    private String outputLog;

    private ExecuteService executeService = new ExecuteServiceImpl();

    public LogComponent(String outputLog) {
        this.outputLog = outputLog;
    }

    public void execute(ExecuteBean executeBean){

        //设置ExecuteLog对象的各属性
        ExecuteLog executeLog = new ExecuteLog(executeBean.getExecute_id(), executeBean.getFunction_id(),
                executeBean.getTestcase_id(), executeBean.getComponent_id(), "", "");
        //替换outputLog中的#{xxx}为实际值
        RegexProcessor regexProcessor = new RegexProcessor();
        outputLog = regexProcessor.replaceStringByMap(outputLog, executeBean.getParaMap());

        //插入日志
        executeService.insertExecuteLog(executeLog, ">>>>>输出日志：" + outputLog);
    }
}
